<?php
class NewsDetailForm extends Form
{
	function __construct()
	{				
		Form::Form('NewsDetailForm');
		
		$id=Url::get('news_id',0);
		
		if($id)
		{
			if(!CGlobal::$news_details)
			{
				CGlobal::$news_details = DB::select("news","id=$id");
			}
			
			if(CGlobal::$news_details && (CGlobal::$news_details['status'] ==1 || (CGlobal::$news_details['status'] == 0 && User::have_permit(ADMIN_NEWS)))){
				$this->news = CGlobal::$news_details;
			}
		}
		
		if(!$this->news){
			Url::redirect('news_list',array('news_catid','azname'));
		}
		else 
			DB::query("UPDATE news SET view_num=view_num+1 WHERE id =".$this->news['id']);

		$news_title		= $this->news['title'];
		$catid			= $this->news['news_catid'];
		
		$str_keywords 	= '';
		$str_catSub 	= '';		
		$meta_keywords 	= '';
		$meta_desc 		= '';
		
		if(isset(CGlobal::$allNewsCategories[$catid]))
		{
			$news_title .= " - ".CGlobal::$allNewsCategories[$catid]['name'];
			
			$curMainCat = CGlobal::$allNewsCategories[$catid];
			
			$str_catSub = $curMainCat['name'];			
			
			if($curMainCat['keywords'])
			{
				$meta_keywords .= ($meta_keywords?', ':'').$curMainCat['keywords'];
			}
			
			if($curMainCat['description'])
			{
				$meta_desc .= ($meta_desc?', ':'').$curMainCat['description'];
			}
		}
		
		if( $this->news['brief']){
			CGlobal::$meta_desc = AZLib::cleanHtml($this->news['brief']);
		}
		elseif( $meta_desc !='' ){				
			CGlobal::$meta_desc = $meta_desc;
		}
		
		if($meta_keywords != ''){
			CGlobal::$keywords = $meta_keywords;
		}
		elseif($str_catSub != ''){
			CGlobal::$keywords = $str_catSub;
		}
		
		CGlobal::$website_title = stripslashes($news_title).' - Tin tức';//CGlobal::$website_title = AznetLib::subString($news_title,0,100,true);
		
		
//		$this->link_css('style/aznet/jquery.lightbox.css');
//		$this->link_js('javascript/jquery/lightbox/jquery.lightbox.js');
	}
	
	function draw()
	{
		global $display;
		
		if(User::is_admin())
		{
			$display->add("is_admin",1);
		}
		
		$display->add('url_home',WEB_DIR);
		
		$display->add('time_create',News::displayTime($this->news['time_created']));
		$display->add('title',stripslashes($this->news['title']));
		$display->add('brief',stripslashes($this->news['brief']));
		$display->add('content',stripslashes($this->news['content']));
		$display->add('pen_name',stripslashes($this->news['pen_name']));
		
		if($this->news['source']!='')
			$display->add('source'," ( theo <i>".stripslashes($this->news['source'])."</i> )");
		else 
			$display->add('source',"");
		
		if(User::have_permit(ADMIN_NEWS)){	
			$display->add('admin_link',News::admin_link($this->news));	
		}
		
		if($this->news['image'])
		{
				
			$display->add('img_full_url',"http://".CGlobal::$img_server[$this->news['img_server']].$this->news['image']);
			$display->add('img_max_path',AZLib::getImageThumbMax($this->news['image'],'',1,$this->news['img_server']));
			
			$display->add('image_title',stripslashes($this->news['image_title']));
			$display->add('image_url',AZLib::getImageThumb($this->news['image'],180,0,0,$this->news['img_server']));//AZLib::safe_title($this->news['title']))
			$display->add('image_oringin',$this->news['image']);
		}
		
		$news_cart = CGlobal::$allNewsCategories[$this->news['news_catid']];
		
		$display->add('news_home_link',Url::build('news'));
		
		if($news_cart)
		{
			$display->add('cat_link',Url::build('news',array('news_catid'=>$news_cart['id'],'azname'=>AZLib::safe_title($news_cart['name']))));
			$display->add('cat_name',$news_cart['name']);
		}
		
		$display->add("share_title", urlencode(CGlobal::$website_title));
		$display->add("share_url", "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
		$display->add("share_des", urlencode(trim(CGlobal::$meta_desc)));
		
		$display->output("NewsDetail");
	}
}
?>